/*
 * @Author: hongbin
 * @Date: 2022-09-22 08:53:22
 * @LastEditors: hongbin
 * @LastEditTime: 2022-09-22 13:11:29
 * @Description:windowResize
 */

export const windowResize = (camera: THREE.PerspectiveCamera, render: typeof window.render) => {
    function onWindowResize() {
        camera.aspect = window.innerWidth / window.innerHeight;
        camera.updateProjectionMatrix();
        window.renderer.setSize(window.innerWidth, window.innerHeight);
    }

    window.addEventListener("resize", onWindowResize);

    /**
     * 移除监听
     */
    const removeListener = () => {
        window.removeEventListener("resize", onWindowResize);
        window.removeEventListener("stoprender", removeListener);
    };

    window.addEventListener("stoprender", removeListener);
};
